home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
H191.ZIP
/
CA29-3.EXE
/
HOST.SRC
< prev
next >
Wrap
Text File
|
1993-07-14
|
20KB
|
718 lines
; trace on ; Debugging
;
; ----- COM-AND Scripted host mode ----------------------------------
;
; Goals:
; o Must autodetect caller's baud rate
; o Must work correctly for modems reporting true CD and otherwise.
; o Must log all activity
;
; Functions:
; o Passworded log-on
; o DIR of current directory
; o CHDIR command
; o UP and DOWNLOADS
; o Graphical path display (using P/D TREED program)
; o Passworded DOS access (dangerous!)
; o Passworded drop-to-DOS using a doorway function
;
; Commenced: 10/29/87 R.McG
; Updated: 2/--/89 R.McG
; 10/--/89 R.McG ZMODEM added
; Ver 1.1: 11/--/90 R.McG HOSETUP added
; 6/--/91 R.McG DROPDOS added
; Ver 1.2: 4/--/93 R.McG (Added SCHEDULER hook for one-call use)
; (Changed to use HOSTTEMP.STR for door rtn)
; (allow sysop to type user commands from kbd)
; --------------------------------------------------------------
; Data for this script are established through the HOSETUP script.
; The drop-to-DOS requires a doorway function (such as DOORWAY,
; by Marshsall Dudley). The only other file requisite to this
; HOST script is the TREED p/d utility.
; --------------------------------------------------------------
;
; Initialize
;
LEGEND "Scripted HOST mode (1.2). Press ESC to exit."
;
; Set default values (in case HOSTDAT does not exist)
;
S20 = "_PARM"(11:14)*","*"_PARM"(0:3) ; Port(4),speed(4)
S21 = "ATE0Q0V1X1S0=2 S7=30 S9=10^M" ; Standard MINIT for HOST
S22 = "****" ; Set default logon password
S23 = "xxxx" ; Set default DOS password
S24 = "" ; Drop to DOS command
;
; Initialize COM related values (This is done here to allow HOSTDAT
; ... edits to override these settings)
;
SET PARITY NONE ; fixed no parity
SET DATA 8 ; fixed 8 data bits
SET STOP 1 ; fixed 1 stop bit
SET MASK ON ; accept 7 or 8 bits
SET CR_IN CR_LF ; Display received c/rs as a cr/lf
SET ASCII UP_LF LF ; Send LFs
SET SOFTFLOW ON ; Allow XON/XOFF
;
; Replace above values from HOSTDAT, if that script exists
;
IF ISSC "HOSTDAT" FCALL "HOSTDAT"
;
; Initialize variables that must be constant
;
S0 = S22 ; Set to our subdirectory
S3 = S23 ; Set subdir for files
SUBDIR S29 ; Read current subdir
DLDIR S28 ; Read current download subdir
;
; Set initial values that do not change port setting
;
LOG MARK ON ; Timestamp logging
CLOG "* Host script loaded"
ON ESCAPE GOSUB End ; Exit routine
SET INAFTER OFF ; Turn off init after hangup
SET ALARM OFF ; Turn off alarm
SET ATIME 1 ; Set alarm time to 1 second
;
; If this is a restart, pickup at the main prompt
;
SET PORT S20(0:3) ; Starting port
IF ISFILE "HOSTTEMP.STR" and ISFILE "HOSTTEMP.BAT"
SET RECHO ON ; Restart - need to reenable
DELETE "HOSTTEMP.STR" ; Done w/the file
LOG OPEN "HOSTLOG" ; .. reenable
CLOG "* Return from drop-to-DOS"
GOTO Main_Prompt
ENDIF
;
; Initialize values that change port setting, and start a new call
;
SET BAUD S20(5:8) ; Starting speed
TRANSMIT "_MESCAPE" ; Initialize modem (modem escape)
GOTO Restart ; Branch around subroutines
;
; -----------------------------------------------------------------------
; Subroutine: End of HOST
; 4/93: Transmit MINIT *before* RESET, in case modem in use by BBS
; is not modem default for COM-AND (MINIT turns off answer)
; -----------------------------------------------------------------------
;
End:
HANGUP ; Hangup the phone
CLOG "* HOST script terminated" ; Log completion
SET DLDIR S28 ; Reset dldir
CHDIR S29 ; Reset to default directory
CLEAR ; Clear screen
MESS "HOST terminated... type Alt-X to exit COM-AND^M^J^M^J"
TRAN "_MINIT" ; Initialize modem from defaults
RESET ; Reset default values
DELETE "\HOSTTEMP.TXT" ; Cleanup
IF ISSC "$$$SCHED" EXECUTE "$$$SCHED" ; And chain back after call
EXIT ; Exit
; -----------------------------------------------------------------------
; Subroutine: Read from the caller into S9 (modified 7/93 for kbd)
; .. This handles 'disconnect' and timeouts, and allows sysop typethru
; -----------------------------------------------------------------
; S27, S28, S29, N30, N27 and TIMER(0) are used in this procedure
; S9 returns the text read (if any)
;
; FLAG(0) off -> Line read correctly
; on --> Disconnect or timeout
; -----------------------------------------------------------------------
; Initialize for loop
;
Read_Comm:
S9 = "" ; Clear buffer
N27 = 0 ; Size of S9 buffer
SET RMODE BINARY ; Binary comm read
;
; Now, sit on the COMM port waiting for a read
;
RCOM100:
SET TIMER ; Set timer for now
WHILE NOT RECEIVE and NOT HITKEY; Loop, awaiting activity
IF NOT CONNECTED GOTO RCOM500; If modem reports CD dropped
TSINCE N28,N29,N30 ; Look at time since start
IF NOT ZERO N28 or N29 GT 3 GOTO RCOM400
ENDWHILE
;
; Catch comm chars
;
IF RECEIVE ; Something on the comm port
RGET S27 1 180 ; .. so read it
IF FIND S27 "^M" GOTO RCOM300; Catch c/r here
GOTO RCOM200 ; And skip to process
ENDIF
;
; Catch sysop (kbd) chars
;
IF HITKEY ; Something on the kbd
KEYGET S27 ; .. so read it
IF FIND S27(0:1) "0d" ; Allow sysop to do c/r
TRANS "!" ; Echo to caller
GOTO RCOM300 ; go handle c/r
ENDIF
IF FIND S27(0:1) "08" ; Allow sysop to do b/s
ITOC 8 S27 ; Place in buffer
S27(1:79) = "" ; and remove remainder
ENDIF
LENGTH S27 N28 ; Take length of read
IF N28 GT 1 ; Must be ascii char
SOUND 100,400 ; Else, bronx cheer
GOTO RCOM100 ; .. and throw away
ENDIF
IF NOT (FIND S27 "^H" and N27 EQ 0) TRANS S27; Echo char to caller
CURSOR N28 N29 ; Read cursor pos
ATSAY N28 N29 (text) S27 ; Echo to console
IF FIND S27 "^H" ; If backspace entered
IF N27 GT 0 DEC N29 ; Backspace cursor position
ELSE ; Not a backspace
INC N29 ; Increment col pos
ENDIF
LOCATE N28 N29 ; Set new cursor pos
ENDIF
;
; Handle the received char - 1st, look for backspaces
;
RCOM200:
IF FIND S27(0:0) "^H" ; Backspace
IF ZERO N27 GOTO RCOM100 ; Don't backspace past rightmost
DEC N27 ; Decrement count so far
IF N27 GT 0 ; If anything remains in buffer
S9 = S9(0:N27-1) ; .. remove last char
ELSE
S9 = "" ; Make null again
ENDIF
GOTO RCOM100 ; And continue looping
ENDIF
;
; Buffer up anything else
;
S9 = S9*S27 ; Concatenate char
INC N27 ; Increment count bufferred
IF N27 LT 80 GOTO RCOM100 ; Loop if we haven't 80
;
; Look at the buffer we've collected
;
RCOM300:
FIND S9 "NO CARRIER" ; Test for message from modem
IF FOUND GOTO RCOM500 ; If modem didn't report 'CD' true
;
; Return 'text read'
;
SET RMODE ASCII ; Normal comm read restored
SET FLAG(0) OFF ; Report to caller
RETURN ; Return with text in S9
;
; Timeout on the call
;
RCOM400:
TRAN "^M^J... autodisconnect due to timeout^M^J"
MESSAGE "^M^J... autodisconnect due to timeout"
GOTO RComm_Exit ; Exit cycle in the usual manner
;
; Disconnect was reported.
;
RCOM500:
MESSAGE "^M^JCaller disconnected"
;
; Read_Comm error exit
;
RComm_Exit:
SET RMODE ASCII ; Normal comm read restored
SET FLAG(0) ON ; Report to caller
RETURN ; Return to the caller
;
; Usages:
; S0 -> main password
; S1 -> ID
; S2 -> Default drive/subdir
; S3 -> DOS password
; S8 -> File name buffer
; S9 -> General read buffer
;
; Begin the sequence...
;
Restart:
CHDIR S29 ; Reset to default drive
SET RECHO OFF ; Turn off echo for us
SET RDISP OFF ; Disable display of rcvd chars
CLEAR ; Clear screen
LOCATE 0,0 ; Set to home
;
; Go into auto answer (echo off, answer on 3rd)
; Also: Return result codes, word form, with CONNECT 1200
;
;
IF NOT ISSC "$$$SCHED" ; If scheduler didn't start us
HANGUP ; HANGUP and leave modem in cmd mode
MESSAGE "^M^JWaiting...!"
PAUSE 3 ; Wait 3 secs for modem to settle
ENDIF
SET BAUD S20(5:8) ; Starting speed
TRANSMIT S21 ; Transmit modem initialization
;
; Wait for a connect
;
WAIT_IT_OUT:
RGET S9 80 180
IF NOT SUCCESS GOTO Wait_IT_Out
FIND S9 "NO CARRIER"
IF FOUND GOTO Exit
FIND S9 "CONNECT"
IF NOT FOUND GOTO WAIT_IT_OUT
;
; Connection established: Adjust our linespeed if need be
;
GOSUB AutoBaud ; Change rate according to CONNECT MSG
;
; Issue a greeting
;
PAUSE 2 ; Let the modem settle
RFLUSH ; Clear junk
TRAN "^M^JThe Flying Scotsman greets you!!^M^J"
SET RECHO ON ; Turn on echo (back to caller)
SET RDISP ON ; Turn on display of rcvd chars
LOG OPEN "HOSTLOG"
;
; Request an ID
;
ID_Query:
MESS "^M^JID prompt: " ; Local console indicator
TRANSMIT "^M^JEnter your ID: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Exit ; If first flag rtns set, disconn and start over
SWITCH S9
CASE "_NULL" ; Test for nothing entered
TRAN "You must be someone^M^J"
GOTO Exit ; Don't let noone in
ENDCASE ; End of ridicule
ENDSWITCH ; End of ID test
CLOG "* Host mode logon by "*S9
;
; Request a password
;
TRANSMIT "^M^JEnter your password: "
LOG SUSPEND
SET RECHO OFF ; Turn of echo of received text
SET RDISPLAY OFF ; Turn off echo to console too
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Exit ; If first flag rtns set, disconn and start over
LOG RESUME ; Restore logging
SET RECHO ON ; Restore echo
SET RDISPLAY ON ; Turn on echo to console again
;
; Test for the main password
;
SWITCH S9
CASE S0 ; Test for match with S0
TRANSMIT "^M^J" ; OK - good password
ENDCASE ; End match with S0
DEFAULT ; Not one of the above
TRANSMIT "Sorry , but you're not authorized."
GOTO Exit ; And disconnect
ENDCASE ; End of DEFAULT
ENDSWITCH
;
; Now - do something
;
Main_Prompt:
MESS "^M^JMain prompt: "; Local console indicator
TRAN "^M^JC)hdir F)ilelist, P)athlist, U)pload, D)ownload, or E)xit: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Exit ; If first flag rtns set, disconn and start over
SWITCH S9 ; Test the entry
CASE "C"
GOTO CHDIR
ENDCASE
CASE "D"
GOTO DOWNLOAD
ENDCASE
CASE "E"
TRAN "Ok... bye^M^J"
GOTO EXIT
ENDCASE
CASE "F"
GOTO FILELIST
ENDCASE
CASE "P"
GOTO PATHLIST
ENDCASE
CASE "U"
GOTO UPLOAD
ENDCASE
CASE "X"
GOTO DOS
ENDCASE
CASE "Y"
GOTO DROPDOS
ENDCASE
CASE "OFF"
TRAN "Ok... bye^M^J"
GOTO EXIT
ENDCASE
;
; Default case for typists
;
DEFAULT
IF FIND S9 "CHDIR" GOTO CHRIR ; If entry contained "CHDIR"
IF FIND S9 "DOWN" GOTO DOWNLOAD ; Try for larger
IF FIND S9 "FILE" GOTO FILELIST ; Try for larger
IF FIND S9 "PATH" GOTO PATHLIST ; Try for larger
IF FIND S9 "UP" GOTO UPLOAD ; Try for larger
IF FIND S9 "DOS" GOTO DOS ; Try for larger
TRAN "^M^JCommand not recognized... try again"
GOTO Main_Prompt ; If none of the above
ENDCASE ; End of DEFAULT
ENDSWITCH
;
; Can't get here because of the DEFAULT in the SWITCH above
;
TRAN "^M^JThank you veddy much.^M^J"
GOTO Main_Prompt
;
; General exit routine - don't GOTO from within a subroutine!!!
;
EXIT:
CLOG "* Host mode exit"
LOG CLOSE ; Turn off logging
MESS "^G" ; Beep to indicate completion
IF ISSC "$$$SCHED" GOTO End ; Hook for scheduler return
GOTO Restart ; And start over
;
; Subroutine: Query for a file name - return in S8
;
File_Query:
MESS "^M^JFname query: "; Local console indicator
TRAN "^M^JEnter the file name: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) RETURN ; If first flag rtns set, done
ASSIGN S8 S9 ; Move fname into another variable
SWITCH S8
CASE "_NULL" ; Test for nothing entered
SET FLAG(1) ON ; Report to caller
RETURN ; Return right here w/ flag set
ENDCASE
ENDSWITCH ; End of ID test
SET FLAG(1) OFF ; Report to caller
RETURN ; Return to caller
;
; XMODEM Upload (up from caller)
;
UPLOAD:
MESS "^M^JUpload from caller"
GOSUB File_Query ; Ask for a file name
IF FLAG(0) GOTO Exit ; If first flag rtns set, disconn and start over
IF FLAG(1) GOTO Main_Prompt; If no file returned, start over
IF ISFILE S8 ; If file exists
TRAN "^M^JFile already exists"
GOTO UPLOAD ; Ask again
ENDIF
MESS "!Method prompt: " ; Local console indicator
TRAN "^M^JW)xmodem, X)modem, Y)modem (X1k), Z)modem, or K)ermit: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Main_prompt; If first flag rtns set, disconn and start over
SWITCH S9 ; Test the entry
CASE "W"
GETFILE WXMODEM S8
ENDCASE
CASE "X"
GETFILE XMODEM S8
ENDCASE
CASE "Y"
GETFILE YMODEM S8
ENDCASE
CASE "Z"
GETFILE ZMODEM
ENDCASE
CASE "K"
GETFILE KERMIT ; FIle name supplied by caller
ENDCASE
DEFAULT
TRAN "^M^JInvalid transfer selection"
GOTO Main_Prompt
ENDCASE
ENDSWITCH
GOTO EOTransfer ; Report success/failure
;
; XMODEM Download (down to caller)
;
DOWNLOAD:
MESS "^M^JDownload to caller"
GOSUB File_Query ; Ask for a file name
IF FLAG(0) GOTO Exit ; If first flag rtns set, disconn and start over
IF FLAG(1) GOTO Main_Prompt; If no file returned, start over
IF NOT ISFILE S8 ; If file doesn't exist
TRAN "^M^JFile doesn't exist"
GOTO DOWNLOAD ; Ask again
ENDIF
MESS "^M^JMethod prompt "
TRAN "^MW)xmodem, X)modem, Y)modem (X1k), Z)modem, K)ermit, or A)scii: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Main_Prompt; If first flag rtns set, disconn and start over
SWITCH S9 ; Test the entry
CASE "A"
SENDFILE ASCII S8
ENDCASE
CASE "W"
SENDFILE WXMODEM S8
ENDCASE
CASE "X"
SENDFILE XMODEM S8
ENDCASE
CASE "Y"
SENDFILE YMODEM S8
ENDCASE
CASE "Z"
SENDFILE ZMODEM S8
ENDCASE
CASE "K"
SENDFILE KERMIT S8
ENDCASE
DEFAULT
TRAN "^M^JInvalid transfer selection"
GOTO Main_Prompt
ENDCASE
ENDSWITCH
GOTO EOTransfer ; Report success/failure
;
; End of transfer... note result on local console
;
EOTRANSFER:
IF NOT SUCCESS
MESS "^M^JTransfer failed"
ELSE
MESS "^M^JTransfer OK"
ENDIF
GOTO Main_Prompt
;
; Filelist... awkward... but it works
;
FILELIST:
MESS "^M^JFilelist command: " ; Local console indicator
TRAN "^M^J Working..." ; May take a moment
DOS "DIR >HOSTTEMP.TXT" ; To a temp file
TRAN "^M^J" ; Send a c/r
SENDFILE ASCII "HOSTTEMP.TXT"
TRAN "^M^J" ; Send a c/r
DOS "DEL HOSTTEMP.TXT" ; Clean up after us
GOTO Main_Prompt ; And continue
;
; CHDIR... Query for a path.
;
CHDIR:
MESS "^M^JCHDIR Command: " ; Local console indicator
TRAN "^M^JEnter the drive:subdirectory: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Main_Prompt; If first flag rtns set, disconn and start over
CHDIR S9 ; Do it.
GOTO Main_Prompt ; And continue
;
; Path tree... awkward... but it works
;
PATHLIST:
MESS "^M^JPathlist command: "; Local console indicator
TRAN "^M^J Working..." ; May take a moment
DOS "Treed >HOSTTEMP.TXT" ; To a temp file
TRAN "^M^J" ; Send a c/r
SENDFILE ASCII "HOSTTEMP.TXT"
TRAN "^M^J" ; Send a c/r
DOS "DEL HOSTTEMP.TXT" ; Clean up after us
GOTO Main_Prompt ; And continue
;
; DOS command: Accept a command and execute it
;
DOS:
GOSUB DOSPSW ; Request a password
IF FAILED GOTO Main_Prompt
;
; DOS... Query for a command
;
MESS "^M^JDOS Command: "; Local console indicator
TRAN "^M^JEnter the command: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO Main_Prompt; If first flag rtns set, disconn and start over
TRAN "^M^J Working..." ; May take a moment
CONCAT S9 ">HOSTTEMP.TXT"
DOS S9 ; Do it.
TRAN "^M^J" ; Send a c/r
SENDFILE ASCII "HOSTTEMP.TXT"
TRAN "^M^J" ; Send a c/r
DOS "DEL HOSTTEMP.TXT" ; Clean up after us
GOTO Main_Prompt ; And continue
;
; DOSPSW Request a password
;
DOSPSW:
MESSAGE "^M^JRequesting DOS password"
LOG SUSPEND ; Turn off logging
SET RECHO OFF ; .. and don't echo passsword
SET RDISPLAY OFF ; Turn off echo to console too
TRANSMIT "^M^JEnter the DOS password: "
GOSUB Read_Comm ; Read into S9
IF FLAG(0) GOTO DOSPERR ; If first flag rtns set, exit, failed
LOG RESUME ; Turn on logging again
SET RECHO ON ; .. and begin echoing again
SET RDISPLAY ON ; Turn on echo to console again
;
; Test for the our password
;
SWITCH S9
CASE S3 ; Test for match with S3
TRANSMIT "^M^J" ; OK - good password
ENDCASE ; End match with S3
DEFAULT ; Not one of the above
TRANSMIT "Sorry , but you're not authorized."
GOTO DOSPERR ; Exit, failed
ENDCASE ; End of DEFAULT
ENDSWITCH
;
; Return with success
;
LOG RESUME ; Restart log
SET SUCCESS ON ; Set indicator for caller
RETURN
;
; Return with success
;
DOSPERR:
LOG RESUME ; Restart log
SET SUCCESS OFF ; Set indicator for caller
RETURN
;
; DROPDOS command: Request a password
;
DROPDOS:
IF NULL S24
TRAN "^M^JCommand not recognized... try again"
GOTO Main_Prompt ; Can't do it
ENDIF
GOSUB DOSPSW ; Request a password
IF FAILED GOTO Main_Prompt
;
; DROPDOS... Build a batch file
;
FOPENO "HOSTTEMP.BAT" TEXT
IF NOT SUCCESS
TRAN "File error - cannot drop to DOS^M^J"
GOTO Main_Prompt
ENDIF
WRITE "ECHO OFF!" ; Start the batch file
S0 = S24 ; Setup up drop to DOS command
PRESERVE S0 ; Make it printable
WRITE S0 ; Write the Drop to DOS command
WRITE "!" ; And a terminating cr
WRITE S29(0:1)*"!" ; Change to drive
IF NOT NULL S29(2:79) WRITE "CD "*S29(2:79)&"!" ; Rtn to original dir
WRITE "COM-AND /q/p/fHOST!" ; inhibit COM-AND.CMD; take modem as set
WRITE "^Z"
FCLOSEO ; And we're done with it
STORE STRING "HOSTTEMP.STR" ; Used by main-line to signal doorway rtn
CLOG "* Drop-to-DOS"
SET TTHRU OFF ; Disable type through
STACK CLEAR ; Place invocation of the batch file
STACK "HOSTTEMP.BAT!" ; .. into BIOS's area
BYE ; Do it.
;
; Auto baudrate detect (according to message in S9)
;
AutoBaud:
IF FIND "_DDOVER" "ON" RETURN ; No autobaud if this set
IF FIND S9 "1200"
SET BAUD 1200 ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "2400"
SET BAUD 2400 ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "4800"
SET BAUD 4800 ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "9600"
SET BAUD 9600 ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "14400" or FIND S9 "14.4"
SET BAUD 14k ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "19200" or FIND S9 "19.2"
SET BAUD 19k ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "38400" or FIND S9 "38.4"
SET BAUD 38k ; Set to new rate
RETURN ; We're done.
ENDIF
IF FIND S9 "57600" or FIND S9 "57.6"
SET BAUD 57k ; Set to new rate
RETURN ; We're done.
ENDIF
;
; None of the above... set to 300
;
SET BAUD 300 ; Set to 1200 baud
RETURN ; We're done.